Foundations of Machine Learning

Practical Lab 2

Submitted by Beena Kurian(student ID: 8946601)

--------------------------------Using matlotlib------------------------------------------

1. PIE CHART
A pie chart helps organize and show data as a percentage of a whole. The table below, can be represented in Pie chart

Recommended Diet
FOOD PERCENTAGE
Fruit 36
Vegetables 14
Dairy 13
Protein 28
Grains 9
In [ ]:
from matplotlib import pyplot as plt
labels = 'Fruit', 'Vegetables', 'Dairy', 'Protein','Grains'
sizes = [36, 14, 13, 28, 9]
explode = (0.3, 0, 0, 0, 0)  # only "explode" the 1st slice (i.e. 'Fruit')
fig, ax = plt.subplots()
ax.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',
       shadow=True, startangle=90)
plt.show()

--------------------------------Using seaborn------------------------------------------

2. BAR PLOT
A bar plot shows the relationship between a numeric and a categoric variable.

In [ ]:
import seaborn as sns
custom_params = {"axes.spines.right": False, "axes.spines.top": False}
sns.set_theme(style="ticks", rc=custom_params)
sns.barplot(x=["2021", "2022", "2023"], y=[750, 1500, 1145])
Out[ ]:
<Axes: >

--------------------------------Using plotly------------------------------------------

3. SCATTER PLOT
It is used to observe relationship between variables. It uses dots to represent the relationship between the variables.

In [ ]:
import plotly
from plotly import express as px
dataframe = px.data.iris()               
fig = px.scatter(dataframe, x="petal_width", y="petal_length",color="species",title="Iris Dataset-Relationship")
fig.show()
plotly.offline.init_notebook_mode()

--------------------------------Using matlotlib------------------------------------------

4. LINE GRAPH
Line graphs are used to track changes over short and long periods of time.

In [ ]:
import pandas as pd
import matplotlib.pyplot as plt
   
placement_data = {'year': [2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023],
        'employment_rate': [4.5, 5.5, 6.5, 7.0, 7.5, 6.0, 4.5, 5.6, 7.5, 9.5]
       }
  
df = pd.DataFrame(placement_data)
  
plt.plot(df['year'], df['employment_rate'], color='green', marker='H')
plt.title('PLACEMENT CELL DATA FOR THE LAST 10 YEARS', fontsize=12)
plt.xlabel('year', fontsize=12)
plt.ylabel('employment rate', fontsize=12)
plt.grid(True)
plt.show()